<?php
namespace app\models;

use laiq\base\Model;
use laiq\db\Connection;

/**
 * 分类Model
 */
class CategoryModel extends Model
{
    protected $table = 'category';

    /**
     * 获取所有分类名
     *
     * @param integer $limit 0=获取所有
     * @param integer $offset
     * @return void
     */    
    public function findCats($limit=20, $offset=0, $key='') {
        if ($offset) {
            $this->where('id', $offset, '>');
        }
        if ($limit) {
            $this->limit($limit);
        }
        $rows = $this->findAll();
        // 结果以key作为键值  
        if ($key && $rows && isset(current($rows)[$key])) {
            $fRows = [];      
            foreach ($rows as $row) {
                $sKey = $row[$key];
                $fRows[$sKey] = $row; 
            }
            $rows = $fRows;
            unset($fRows);
        } 
        return $rows; 
    }
}